package com.ht.right.util;

import java.io.FileInputStream;
import java.io.InputStream;

import javax.servlet.http.HttpServletResponse;

public class FileCommonUtil {
	//文件下载
	public static void dowloadFile(String fileName,String path,HttpServletResponse response){
		InputStream inStream =null;
		try {
			inStream = new FileInputStream(path);
			String name = fileName+path.substring(path.lastIndexOf("."));
			name = new String(name.getBytes("GBK"),"ISO8859-1");
			//设置输出格式
			response.reset();
			response.setContentType("bin");
			response.addHeader("Content-Disposition", "attachment;filename="+name);
			//循环输出流数据
			byte[] b = new byte[100];
			int len ;
			while((len = inStream.read(b))>0)
				response.getOutputStream().write(b, 0, len);
		} catch (Exception e) {
			e.printStackTrace();
		}
	} 

}
